package com.elm.controller;

import com.elm.po.DeliveryAddress;
import com.elm.service.DeliveryAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/api/address")
public class DeliveryAddressController {
    @Autowired
    private DeliveryAddressService addressService;

    @GetMapping("/byUser/{userId}")
    public List<DeliveryAddress> getDeliveryAddressByUserId(@PathVariable String userId) {
        return addressService.getDeliveryAddressByUserId(userId);
    }

    @PostMapping("/save")
    public int saveDeliveryAddress(@RequestBody DeliveryAddress deliveryAddress) {
        return addressService.saveDeliveryAddress(deliveryAddress);
    }

    @GetMapping("/{daId}")
    public DeliveryAddress getDeliveryAddressById(@PathVariable Integer daId) {
        return addressService.getDeliveryAddressById(daId);
    }

    @PutMapping("/update")
    public int updateDeliveryAddress(@RequestBody DeliveryAddress deliveryAddress) {
        return addressService.updateDeliveryAddress(deliveryAddress);
    }

    @DeleteMapping("/{daId}")
    public int removeDeliveryAddress(@PathVariable Integer daId) {
        return addressService.removeDeliveryAddress(daId);
    }

    @PutMapping("/default/{daId}")
    public int setDefaultAddress(@PathVariable Integer daId) {
        return addressService.setDefaultAddress(daId);
    }
}